﻿using System;
using System.Runtime.InteropServices;
using System.Collections.Generic;
using System.Text;

namespace PickGold.Api
{
	/// <summary>
	/// 
	/// </summary>
	public static class MsVfw32
	{
		/// <summary>
		/// 
		/// </summary>
		public const string DLL = Common.DLL_MSVFW32;

		[DllImport(DLL)]
		public static extern int ICCompressGetFormat(
			//int hic, 
			IntPtr hic,
			ref BITMAPINFO lpbiInput,
			ref BITMAPINFO lpbiOutput
			);

		[DllImport(DLL)]
		public static extern int ICDecompressBegin(
			//int hic, 
			IntPtr hic,
			ref BITMAPINFO lpbiInput,
			ref BITMAPINFO lpbiOutput
			);

		[DllImport(DLL)]
		public static extern int ICDecompressGetFormat(
			//int hic, 
			IntPtr hic,
			ref BITMAPINFO lpbiInput,
			ref BITMAPINFO lpbiOutput
			);

		//[DllImport(DLL)]
		//public static extern void ICSeqCompressFrameEnd(ref COMPVARS pc);

		[DllImport(DLL)]
		public static extern int ICCompressGetFormatSize(
			int hic,
			ref BITMAPINFO lpbiInput
			);

		//[DllImport(DLL)]
		//public static extern bool ICSeqCompressFrameStart(
		//    ref COMPVARS pc,
		//    //ref BITMAPINFO lpbiIn 
		//    ref BITMAPINFO lpbiIn
		//    );

		//[DllImport(DLL)]
		//public static extern IntPtr ICSeqCompressFrame(
		//    ref COMPVARS pc,
		//    uint uiFlags,
		//    byte[] lpBits,
		//    ref bool pfKey,
		//    //ref ushort pfKey, 
		//    //ref long plSize 
		//    ref int plSize
		//    );

		//[DllImport(DLL, CharSet = CharSet.Ansi)]
		//public static extern int ICGetInfo(
		//    int hic,
		//    ICINFO lpicinfo,
		//    int cb
		//    );

		//[DllImport(DLL)]
		//public static extern bool ICCompressorChoose(
		//    IntPtr hwnd,
		//    int uiFlags,
		//    //int pvIn, 
		//    //int lpData, 
		//    IntPtr pvIn,
		//    IntPtr lpData,
		//    ref COMPVARS pc,
		//    string lpszTitle
		//    );

		[DllImport(DLL)]
		public static extern int ICLocate(
			int fccType,
			int fccHandler,
			ref BITMAPINFOHEADER lpbiIn,
			ref BITMAPINFOHEADER lpbiOut,
			short wFlags
			);

		//[DllImport(DLL), PreserveSig]
		//public static extern int ICOpen(uint fccType, uint fccHandler, ICMODE wMode);
		//public static extern IntPtr ICOpen(uint fccType, uint fccHandler, uint wmode); // ICMODE wMode); 

		[DllImport(DLL), PreserveSig]
		public static extern int ICDecompressOpen(
			int fccType,
			int fccHandler,
			ref BITMAPINFOHEADER lpbiIn,
			ref BITMAPINFOHEADER lpbiOut
			);

		[DllImport(DLL)]
		public static extern int ICClose(int hic);

		[DllImport(DLL)]
		public static extern int ICCompress(
			int hic,
			int dwFlags,        // flags 
			ref BITMAPINFOHEADER lpbiOutput,    // output format 
			IntPtr lpData,        // output data 
			ref BITMAPINFOHEADER lpbiInput,      // format of frame to compress 
			IntPtr lpBits,        // frame data to compress 
			int lpckid,        // ckid for data in AVI file 
			int lpdwFlags,      // flags in the AVI index. 
			int lFrameNum,      // frame number of seq. 
			int dwFrameSize,    // reqested size in bytes. (if non zero) 
			int dwQuality,      // quality within one frame 
			int lpbiPrev,      // format of previous frame 
			int lpPrev          // previous frame 
			);

		[DllImport(DLL)]
		public static extern int ICDecompress(
			int hic,
			//IntPtr hic, 
			//int dwFlags, 
			uint dwFlags,
			ref BITMAPINFOHEADER lpbiFormat,
			byte[] lpData,
			ref BITMAPINFOHEADER lpbi,
			byte[] lpBits
			);

		[DllImport(DLL)]
		public static extern int ICSendMessage(int hic, int msg, ref BITMAPINFO dw1, ref BITMAPINFO dw2);

		[DllImport(DLL)]
		public static extern int ICSendMessage(int hic, int msg, int dw1, int dw2);

		//[DllImport(DLL)]
		//public static extern int ICSendMessage(int hic, int msg, ICINFO dw1, int dw2);

		public const int DRV_USER = 0x4000;
		public const int ICM_USER = (DRV_USER + 0x0000);
		public const int ICM_COMPRESS_BEGIN = (ICM_USER + 7);    // begin a series of compress calls. 
		public const int ICM_COMPRESS = (ICM_USER + 8);  // compress a frame 
		public const int ICM_COMPRESS_END = (ICM_USER + 9);  // end of a series of compress calls. 
		public const int ICM_COMPRESS_GET_FORMAT = (ICM_USER + 4);
		public const int ICM_DECOMPRESS_BEGIN = (ICM_USER + 12);  // start a series of decompress calls 
		public const int ICM_DECOMPRESS = (ICM_USER + 13);  // decompress a frame 
		public const int ICM_DECOMPRESS_END = (ICM_USER + 14);
		public const int ICERR_OK = 0x0;
	}
}
